package goroutine

import (
	"fmt"
	"runtime"
	"time"
)

func GRun() {
	go func() {
		for i := 0; i < 2; i++ {
			fmt.Println("inner2", i)
		}
	}()
	go func() {
		for i := 0; i < 2; i++ {
			fmt.Println("inner", i)
		}
	}()
	for i := 0; i < 2; i++ {
		runtime.Gosched() // 切换一个G来实现
		fmt.Println("outter", i)
	}
	time.Sleep(time.Second)
}

func GRunExit() {
	runtime.GOMAXPROCS(6)

	go func() {
		for i := 0; i < 2; i++ {
			fmt.Println("inner", i)
			runtime.Goexit() // 切换一个G来实现
		}
	}()
	for i := 0; i < 2; i++ {
		fmt.Println("outter", i)
	}
	time.Sleep(500)
}
